//
// Created by Dell on 2021/12/4.
//

#include <iostream>
using namespace std;
struct  node{
    int data;
    node *left = nullptr,*right = nullptr;
};
int pre[5]={1,2,4,5,3},in[5]={4,2,5,1,3};
node *create(int preL,int preR,int inL,int inR){
    if(preL>preR){
        return nullptr;
    }
    node * root = new node();
    root->data = pre[preL];
    int k;
    for(k = inL;k<=inR;++k){
        if(in[k] == pre[preL]){
            break;
        }
    }
    int numLeft = (k - inL);
    root->left = create(preL+1,preL+numLeft,inL,k-1);
    root->right = create(preR+numLeft+1,preR,k+1,inR);
    return root;
}

int main(){

    node * root = create(0,4,0,4);
    printf("%d",root->data);
    return 0;
}

